package ModelLayer;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class for DvdCon.
 */
public class DvdConTest
{
    private ModelLayer.DvdCon dvdCon1;

    /**
     * Default constructor for test class DvdConTest
     */
    public DvdConTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
        dvdCon1 = ModelLayer.DvdCon.getInstance();
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
        dvdCon1.clearDvds();
    }

    @Test
    /*
     * Test that dvd is properly added to dvdCon
     */
    public void addDvdTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        dvdCon1.addDvd(dvd1);
        assertEquals(1, dvdCon1.getDvdsSize());        
    }

    @Test
    /*
     * Test that dvd is deleted
     */
    public void deleteDvdTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        dvdCon1.addDvd(dvd1);
        assertEquals(1, dvdCon1.getDvdsSize());
        dvdCon1.deleteDvd(dvd1);
        assertEquals(0, dvdCon1.getDvdsSize());
    }

    @Test
    /*
     * Checks that findDvd returns dvd with title matching the search string
     */
    public void findDvdTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        ModelLayer.Dvd dvd2 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        dvdCon1.addDvd(dvd1);
        dvdCon1.addDvd(dvd2);
        ModelLayer.Dvd dvd3 = dvdCon1.findDvd("Harry Potter 4");
        assertEquals(dvd2, dvd3);
    }

    @Test
    /*
     * Checks that findDVD returns null if dvd title does not match existing dvd
     */
    public void findDvdNotThereTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        ModelLayer.Dvd dvd2 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        dvdCon1.addDvd(dvd1);
        dvdCon1.addDvd(dvd2);
        assertEquals(null, dvdCon1.findDvd("Teletubbies Adventure"));        
    }

    @Test
    /*
     * Test that findcopy return the copy which matches the search string
     */
    public void findCopyTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        ModelLayer.Dvd dvd2 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        dvdCon1.addDvd(dvd1);
        dvdCon1.addDvd(dvd2);
        Copy copy1 = new Copy("1", "2013", "2000");
        Copy copy2 = new Copy("2", "2013", "2000");
        dvd1.addCopy(copy1);
        dvd2.addCopy(copy2);
        assertEquals(copy2, dvdCon1.findCopy("2"));
    }
    
    @Test
    /*
     * Test that findCopy returns null if search string doesn't match any copy
     */
    public void findCopyNotThereTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        ModelLayer.Dvd dvd2 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        dvdCon1.addDvd(dvd1);
        dvdCon1.addDvd(dvd2);
        Copy copy1 = new Copy("1", "2013", "2000");
        Copy copy2 = new Copy("2", "2013", "2000");
        dvd1.addCopy(copy1);
        dvd2.addCopy(copy2);
        assertEquals(null, dvdCon1.findCopy("4"));
    }
    
    @Test
    /*
     * Test that findCopy returns null if there are no copies in dvd
     */
    public void findCopyEmptyTest()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("ABAB", "Die Hard", "Madonna", "1980");
        ModelLayer.Dvd dvd2 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        dvdCon1.addDvd(dvd1);
        dvdCon1.addDvd(dvd2);
        assertEquals(null, dvdCon1.findCopy("1"));
    }
    
    @Test
    /*
     * Test that findCopy returns null if there are no dvds to search in
     */
    public void findCopyNoPersonsTest()
    {
        assertEquals(null, dvdCon1.findCopy("11"));
    }
}

